#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QDebug>
#include <QDateTimeEdit>
#include <QDateTime>
#include <QLineEdit>
#include <QTime>
#include <QDate>
#include <QComboBox>
#include <QByteArray>
#include <QtCore/QTimer>
#include <QInputDialog>
#include <QString>
#include <QMessageBox>
#include <QAction>

#include "parawidget.h"
#include "mychart.h"
#include "mychartview.h"
#include "subthread1.h"
#include "database.h"

#include<iostream>
using namespace std;


QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    void MyPushButtonInit();
    void SysConfigAfterConnected();
    quint8 SerialPortRxDataProcess(quint8 *buf,quint8 len);
    void SerialTxPocket(unsigned char * buf,uint8_t len);
    void DrawPoint(quint8* buf);
    void DataBaseInit(void);
    void PutParaIntoDataBase(void);

signals:
    void PutDataIntoDB(QTime time,qreal vms,qreal tms);

protected:
    void closeEvent(QCloseEvent *event);

private slots:
    void DateAndTimeUpdate();
    void SetTrPara(float value);
    void SetTzPara(float value);
    void SetDeltaKPara(float value);
    void SetKParaPara(float value);
    void SerialErrorHandle(QSerialPort::SerialPortError error);
    void SetTrackPara(quint8 whichPara,float Value);

    void SetAWFAPara(quint8 whichPara,float Value);

    void SerialDataReadAndProcess();

    void on_pushButton_openSerial_clicked();

    void on_pushButton_serialScan_clicked();

    void on_pushButton_closeSerial_clicked();

    void on_pushButton_timeCalibration_clicked();

    void on_pushButton_locationCalibration_clicked();

    void on_pushButton_textEditClear_clicked();

    void on_pushButton_shDynaicChart_clicked();

    void on_pushButton_shStaticChart_clicked();

    void on_pushButton_timeGet_clicked();

    void on_pushButton_locationGet_clicked();

    void on_pushButton_sysParaGet_clicked();

    void on_pushButton_getScalerPara_clicked();

    void on_pushButton_show_hide_sysPara_clicked();

    void on_pushButton_clearLocationInfoinRom_clicked();

    void on_pushButton_ELcAZc_clicked();

    void on_pushButton_trackPara_clicked();

    void on_pushButton_getAWFA_Para_clicked();

    void on_pushButton_Tass_clicked();

    void on_pushButton_showData_clicked();

    void on_pushButton_putParaIntoDB_clicked();

    void on_pushButton_antebbaPosition_clicked();

    void on_pushButton_startTrack_clicked();

    void on_pushButton_stopTrack_clicked();

    void on_pushButton_toTargetSet_clicked();

private:
    Ui::MainWindow *ui;
    QSerialPort    *serial;
    QTimer *m_timer;
    unsigned int Serial_RX_BUF_MX; //不要大于 uint8_t 的最大值
    //画图相关
    MyChart *dynamic_chart;
    MyChart *static_chart;
    MyChartView *dynamic_cview;
    MyChartView *static_cview;
    //参数相关
    ParaWidget *myParaWidget;
    //数据接收处理的子线程
    SubThread1 *db_T;
    QThread *thread_1;
    //变量
    float Tg;
    float Vg;
    float Vss;
    /**/
    float Tass;
    float DeltaK;

    QString dateStr;
    database* dbView;
};
#endif // MAINWINDOW_H
